const oldRoutesConfig = [
  {
    children: [
      {
        children: [
          { router: "workplace" },
          { router: "analysis" },
          {
            children: [{ router: "workplaces" }],
            router: "form",
          },
        ],
        router: "dashboard",
      },
      {
        children: [
          {
            router: "basicForm",
            children: [{
              children: [{ router: "dashboard" }],
              router: "form",
            }]
          },
          { router: "stepForm" },
          { router: "advanceForm" },
          { router: "analysis" },
        ],
        router: "form_1",
      },
      {
        router: "basicForm",
      },
    ],
    router: "root",
  },
];

const array = ["analysis", "basicForm", "dashboard"];

array.push();
arrayMap = {};
array.forEach(item => {
  arrayMap[item] = true;
});
console.log(arrayMap);
function gen() {
  let newConfig = genItem(oldRoutesConfig);
  return newConfig
}
function genItem(ro) {
  if (!ro) { return; }
  for (let i = 0; i < ro.length; i++) {
    if (!arrayMap[ro[i].router] && !ro[i].children) {
      ro.splice(i, 1);
      i--;
      continue;
    }
    genItem(ro[i].children);
    if (!arrayMap[ro[i].router] && (!ro[i].children || ro[i].children.length === 0)) {
      ro.splice(i, 1);
      i--;
    }
  }
  return ro
}
let ac = JSON.stringify(gen())

console.log(ac);